<template>
  <div>
    <h1>权益列表</h1>
    <table class="table table-bordered">
      <tbody>
        <tr>
          <td>序号</td>
          <td>名称</td>
          <td>状态</td>
          <td>操作</td>
        </tr>
        <tr v-for="a in info.list">
          <td>{{ a.qid }}</td>
          <td>{{ a.qname }}</td>
          <td>
            <span v-if="a.qtype == 1">启用</span>
            <span v-if="a.qtype == 0">禁用</span>
          </td>
          <td>
            <input type="button" value="修改状态" @click="del(a.qid)" />
            <input type="button" value="删除" @click="up(a.qid)" />
          </td>
        </tr>
      </tbody>
    </table>
  </div>
</template>
<script setup lang="ts">
import { ref, onMounted, reactive } from "vue";
import axios from "axios";
import { useRoute, useRouter } from "vue-router";
const router = useRouter();
const route = useRoute();

onMounted(() => {
  list();
});
let info: any = reactive({
  list: [],
});
const del = (qid: any) => {
    let f = confirm("确认操作吗");
  if (f) {
    axios({
      url: "/api/User/UpQuan",
      method: "get",
      params: { qid: qid },
    }).then((res) => {
      console.log(res);
      if (res.data > 0) {
        alert("修改成功");
        list();
        return;
      } else {
        alert("修改失败");
        return;
      }
    });
  }
};
const up = (qid: any) => {
    let f = confirm("确认操作吗");
  if (f) {
    axios({
      url: "/api/User/Del",
      method: "get",
      params: { qid: qid },
    }).then((res) => {
      console.log(res);
      if (res.data > 0) {
        alert("删除成功");
        list();
        return;
      } else {
        alert("删除失败");
        return;
      }
    });
  }
};
const list = () => {
  axios({
    url: "/api/User/GetQuan",
    method: "get",
  }).then((res) => {
    console.log(res);
    info.list = res.data;
  });
};
</script>

<style scoped></style>
